<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>注册</title>
		<link rel="stylesheet" type="text/css" href="css/public.css"/>
		<link rel="stylesheet" type="text/css" href="css/login.css"/>
	</head>
	<body>
		<!-------------------reg-------------------------->
		<div class="reg">
			<form >
				<h1><a href="index.html"><img src="img/temp/logo.png"></a></h1>
				<p>用户注册</p>
				<p><input type="text" name="Bape" value="" placeholder="请输入手机号" ></p>
				<p><input type="password" name="paw1" value="" placeholder="以字母开头，长度在6~18之间，只能包含字符、数字和下划线" ></p>
				<p><input type="password" name="paw2" value="" placeholder="请确认密码" ></p>
				<p class="txtL txt"><input class="code" type="text" name="" value="" placeholder="验证码" ><a href="#2" id="YZM" style="color:white;text-decoration:none;background: red;margin-left: 30px; height: 400px;width: 420px;padding: 10px 6px;" onclick="javaScript:switchover()"></a></p>
				<p><button style="height: 40px;width: 120px;background: red" type="button" onclick="javaScript:xz()">注冊</button></p>
				<p class="txtL txt">完成此注册，即表明您同意了我们的<a href="#"><使用条款和隐私策略></a></p>
				<p class="txt"><a href="login.html"><span></span>已有账号登录</a></p>
				<!--<a href="#" class="off"><img src="img/temp/off.png"></a>-->
			</form>
		</div>

	</body>
	<script src="https://cdn.bootcss.com/jquery/3.3.0/jquery.js"></script>
	<script type="text/javascript" src="js/jquery.min.js" ></script>
	<script type="text/javascript" src="js/jquery.citys.js"></script>
<script>
    //账号必须为电话
    var pattern = /^1([358][0-9]|4[579]|66|7[0135678]|9[89])[0-9]{8}$/;
    //请输入以字母开头，长度在6~18之间，只能包含字符、数字和下划线
    var passs=/^[a-zA-Z]\w{5,17}$/;
    $("[name='Bape']").change(function () {
        var email = $(this).val();
        if (pattern.test(email) == false) {
            alert("请输入正确手机号码");
            return false;
        }
    })
	$("[name='paw1']").change(function () {
        var paw1 = $(this).val();
        if(passs.test(paw1)==false){
            alert("以字母开头，长度在6~18之间，只能包含字符、数字和下划线");
            return false;
        }
    })

	$("[name='paw2']").change(function () {
	    var paw1 =$("[name='paw1']").val();
        var paw2 = $(this).val();
		if(paw1!=null&&paw1!=''){
            if (paw1!=paw2) {
                alert("两次密码不一致");
                return false;
            }
		}
    })
   function xz() {
       var email = $("[name='Bape']").val();
	   var paw1 = $("[name='paw1']").val();
	   var paw2 = $("[name='paw2']").val();
	   var yzm1 = $(".code").val()
	   var yzm2 = $("#YZM").text();
       if (email ==""||email==null||paw1==""||paw1==null) {
           alert("账号密码不能为空")
           return false;
       }
       if (yzm1==""||yzm1==null){
           alert("验证码不能为空")
           return false;
       }
       if (paw1 !=paw2) {
           alert("两次密码不一致")
           return false;
       }
       if (yzm1 !=yzm2) {
           alert("验证码错误")
           return false;
       }

       if (pattern.test(email) == false) {
           alert("请输入正确手机号码");
           return false;
       }
	   if(passs.test(paw1)==false){
			alert("以字母开头，长度在6~18之间，只能包含字符、数字和下划线")
		   return false;
	   }
				   $.ajax({
					   url: "http://localhost:8080/reg2",
					   type: "post",
					   data: {"email": email, "paw1": paw1},
					   success: function (reg2) {
						   if (reg2.success) {
							   var data =reg2.data;
							   if (data > 0) {
								   alert("注册成功")
							   } else {
								   alert("注册错误")
							   }
							   location.href = "login.html";
						   }
					   },
					   error: function () {
						   console.log("出现未知错误")
					   }
				   })
   }
</script>
	<script language=javascript>
		$(function () {
		    console.log($(".txtL #YZM").text());
		    if($(".txtL #YZM").text()=='') {
                var rndnumb = "";
                //产生6位定长的随机数
                for (i = 1; i <= 6; i++) {
                    n = Math.floor(Math.random() * 10);
                    rndnumb = rndnumb + n;
                }
                $(".txtL  #YZM").text(rndnumb);
            }
        })
		function switchover() {
			var rndnumb="";
			//产生6位定长的随机数
			for (i=1;i<=6;i++){
				n = Math.floor(Math.random()*10);
				rndnumb= rndnumb + n;
			}
			$(".txtL #YZM").text(rndnumb);
		}
	</script>
	<script type="text/javascript">
		var $town = $('#demo3 select[name="town"]');
		var townFormat = function(info){
			$town.hide().empty();
			if(info['code']%1e4&&info['code']<7e5){	//是否为“区”且不是港澳台地区
				$.ajax({
					url:'http://passer-by.com/data_location/town/'+info['code']+'.json',
					dataType:'json',
					success:function(town){
						$town.show();
						for(i in town){
							$town.append('<option value="'+i+'">'+town[i]+'</option>');
						}
					}
				});
			}
		};
		$('#demo3').citys({
			province:'福建',
			city:'厦门',
			area:'思明',
			onChange:function(info){
				townFormat(info);
			}
		},function(api){
			var info = api.getInfo();
			townFormat(info);
		});
	</script>
</html>
